drop: Ensure all relevant formats are available
authorBenjamin Otte <otte@redhat.com>
Sat, 15 Feb 2020 19:02:44 +0000 (20:02 +0100)
committerBenjamin Otte <otte@redhat.com>
Sat, 15 Feb 2020 19:02:44 +0000 (20:02 +0100)
1. GdkDrop does deserialization, so add the deserialize formats

2. If the drop is local, we can copy straight from the drag, so we can
   also copy all its formats. This fixes cases where the backend would
   drop formats it doesn't support.

gdk/gdkdrop.c

index a0accf74649d00327b4ee97021f26fb8178333dc..9871d1c77685db567ae16a9e9886c3f4bbe475b1 100644 (file)
@@ -162,6 +162,23 @@ gdk_drop_read_local_finish (GdkDrop         *self,
   return g_task_propagate_pointer (G_TASK (result), error);
 }
 
+static void
+gdk_drop_add_formats (GdkDrop           *self,
+                      GdkContentFormats *formats)
+{
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+  formats = gdk_content_formats_union_deserialize_gtypes (gdk_content_formats_ref (formats));
+
+  if (priv->formats)
+    {
+      formats = gdk_content_formats_union (formats, priv->formats);
+      gdk_content_formats_unref (priv->formats);
+    }
+
+  priv->formats = formats;
+}
+
 static void
 gdk_drop_set_property (GObject      *gobject,
                        guint         prop_id,
@@ -186,10 +203,11 @@ gdk_drop_set_property (GObject      *gobject,
 
     case PROP_DRAG:
       priv->drag = g_value_dup_object (value);
+      gdk_drop_add_formats (self, gdk_drag_get_formats (priv->drag));
       break;
 
     case PROP_FORMATS:
-      priv->formats = g_value_dup_boxed (value);
+      gdk_drop_add_formats (self, g_value_get_boxed (value));
       g_assert (priv->formats != NULL);
       break;